Milvus Search
- class towhee.hub.builtin.operators.milvus_search.milvus_search(collection, **kwargs)[source]
Search for embedding vectors in Milvus. Note that the Milvus collection has data before searching, refer to DataCollection Mixin to_milvus.
- Parameters
collection (str or pymilvus.Collection) – The collection name or pymilvus.Collection in Milvus.
kwargs –
The kwargs with collection.search, refer to https://milvus.io/docs/v2.0.x/search.md#Prepare-search-parameters. And the anns_field defaults to the vector field name, limit defaults to 10, and metric_type in param defaults to ‘L2’ if there has no index(FLAT), and for default index param:
IVF_FLAT: {“params”: {“nprobe”: 10}}, IVF_SQ8: {“params”: {“nprobe”: 10}}, IVF_PQ: {“params”: {“nprobe”: 10}}, HNSW: {“params”: {“ef”: 10}}, IVF_HNSW: {“params”: {“nprobe”: 10, “ef”: 10}}, RHNSW_FLAT: {“params”: {“ef”: 10}}, RHNSW_SQ: {“params”: {“ef”: 10}}, RHNSW_PQ: {“params”: {“ef”: 10}}, ANNOY: {“params”: {“search_k”: 10}}.
Examples:
>>> import towhee >>> from pymilvus import connections >>> connections.connect(host='localhost', port='19530') >>> ( ... towhee.glob['path']('./*.jpg') ... .image_decode['path', 'img']() ... .image_embedding.timm['img', 'vec'](model_name='resnet50') ... .milvus_search['vec', 'results'](collection='test') ... .to_list() ... ) [<Entity dict_keys(['path', 'img', 'vec', 'results'])>, <Entity dict_keys(['path', 'img', 'vec', 'results'])>]